<%@page import="org.shop.entity.security.MyUserDetail" %>
<%@page import="org.shop.util.ObjUtil" %>
<%@page import="org.springframework.security.core.context.SecurityContextImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

    SecurityContextImpl securityContextImpl = (SecurityContextImpl) request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
    MyUserDetail ud = null;
    Byte state = 1;
    if (ObjUtil.isNotNullAndEmpty(securityContextImpl)) {
        ud = (MyUserDetail) securityContextImpl.getAuthentication().getPrincipal();
        state = ud.getState();
    }
%>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1 user-scalable=0">
    <title>问答</title>
    <link rel="stylesheet" href="<%=basePath%>assets/css/public.css">
    <link rel="stylesheet" href="<%=basePath%>assets/css/page.css">
    <link rel="stylesheet" href="<%=basePath%>assets/font-awesome-4.7.0/css/font-awesome.min.css">
    <script src="<%=basePath%>assets/js/jquery-1.8.3.min.js"></script>
    <script src="<%=basePath%>assets/js/fontSize.js"></script>
    <link href="<%=basePath%>/assets/layer/mobile/need/layer.css" rel="stylesheet" type="text/css">
	<script src="<%=basePath%>/assets/layer/mobile/layer.js"></script>
    <style>
        body {
            padding-top: 0.85rem;
            padding-bottom: 1.6rem;
        }

        .header_ul li {
            float: left;
            width: 25%;
        }

        .header_ul li a {
            font-size: 0.28rem;
            height: 0.75rem;
            line-height: 0.8rem;
            padding: 0 0.2rem;
            display: inline-block;
        }

        .header_ul li a.active {
            color: #FF3D20;
            border-bottom: 2px solid #FF3D20;
        }

        .answer_list {
            border-bottom: 8px solid #F3F1F1;
        }

        .answer_info {
            border-top: 8px solid #F3F1F1;
            padding: 0.2rem;
        }

        .photo {
            width: 0.8rem;
        }

        .photo img {
            width: 0.7rem;
            height: 0.7rem;
            border-radius: 50%;
        }

        .name {
            font-size: 0.26rem;
        }

        .time {
            color: #989898;
            font-size: 0.24rem;
        }

        .answer_amount {
            width: 0.8rem;
            height: 0.68rem;
            border-radius: 50%;
            background-color: #FF3F25;
            color: #fff;
            font-size: 0.2rem;
            line-height: 0.3rem;
            text-align: center;
            padding-top: 0.12rem;
        }

        .answer_amount i {
            font-size: 0.26rem;
        }

        .question_detail {
            font-size: 0.28rem;
            word-break: break-all;
        }

        .fixed_btn {
            width: 0.6rem;
            height: 0.6rem;
            border-radius: 50%;
            position: fixed;
            right: 0.4rem;
            bottom: 1.2rem;
        }

        .fixed_btn img {
            width: 100%;
        }

        .find a .img {
            display: none;
        }

        .find a .img2 {
            display: block;
        }
        .find a p{
            color: #FF3F25;
        }
    </style>
</head>
<body>
<input id="basePath" type="hidden" value="<%=basePath%>">
<div class="header">
    <ul class="header_ul">
        <li class="forum"><a>论坛</a></li>
        <li class="question_answer"><a class="active">问答</a></li>
        <li class="activity"><a>活动</a></li>
        <li class="invite"><a>招聘</a></li>
    </ul>
</div>
<div class="answer_list"></div>
<div class="fixed_btn">
    <img src="<%=basePath%>assets/images/add.png" alt="" onclick="">
</div>
<%@ include file="../footer.jsp" %>
</body>
<script>
    //滚动加载
    var geting = false;//是否加载信息，默认为false
    var currentPage = 1;//当前页
    var pageSize = 10;//每页数据数
    $(function () {
        $(".header_ul a").click(function () {
            $(".header_ul a").removeClass("active");
            $(this).addClass("active");
        });
        $(".forum").click(function () {
            window.location.href = "<%=basePath%>jsp/app/find/forum.jsp";
        });
        $(".answer_info").click(function () {
            window.location.href = "<%=basePath%>jsp/app/find/questionsAnswersDetails.jsp";
        })

        getData();

        $(window).scroll(function () {
            if (geting) {
                return;
            }
            var scrollTop = $(this).scrollTop();
            var scrollHeight = $(document).height();
            var windowHeight = $(this).height();
            if (scrollTop + windowHeight == scrollHeight) {
                currentPage++;
                getData();
            }

        });
    })

    //获取数据
    function getData() {
        geting = true;
        $.ajax({
            url: "<%=basePath%>app/getQuestionList",
            async: false,
            dataType: "json",
            type: "post",
            data: {
                "currentPage": currentPage,
                "pageSize": pageSize
            },
            success: function (data) {
                $.each(data, function (i, item) {
                    var html = '<a href="<%=basePath%>app/getQuestionDetails?questionId=' + item.questionId + '">' +
                        '<div class="answer_info">' +
                        '<div class="question clearFirx">' +
                        '<div class="photo float_l">' +
                        '<img src="<%=basePath%>app/getGoodsPhotoByName?goodsImage='+item.userPhoto+'" alt="">' +
                        '</div>' +
                        '<div class="info float_l">' +
                        '<span class="name">' + item.userName + '</span><br>' +
                        '<span class="time">' + item.createDate + '</span>' +
                        '</div>' +
                        '<div class="answer_amount float_r clearFirx">' +
                        '<i>' + item.questionAnswerCount + '</i><br>回答' +
                        '</div>' +
                        '</div>' +
                        '<div class="question_detail">' + item.content + '</div>' +
                        '</div>' +
                        '</a>'
                    $(".answer_list").append(html);
                    geting = false;
                });
            },
            error: function (data) {
            	layer.open({
				    content: '网络错误~'
				    ,skin: 'msg'
				    ,time: 3 //3秒后自动关闭
				  });
            }
        })
    }
    $(".activity_details").click(function () {
        window.location.href = "<%=basePath%>jsp/app/find/activity_details.jsp";
    });
    $(".forum").click(function () {
        window.location.href = "<%=basePath%>jsp/app/find/forum.jsp";
    });
    $(".activity").click(function () {
        window.location.href = "<%=basePath%>jsp/app/find/activity.jsp";
    });
    $(".invite").click(function () {
        window.location.href = "<%=basePath%>jsp/app/find/invite.jsp";
    });
</script>
</html>
